import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;


public class Iten extends Sprite {
	
	BufferedImage image = null;
	int mapIndex = 0;
	int index = 0;
	int largura;
	int altura;
	boolean isAlive = false;
	boolean potion = false;
	boolean precionou = false;
	boolean bAction = false;
	
	public Iten(float x,float y,BufferedImage img,int largura,int altura, int indexIten,boolean potion){
		image = img;
		X = x;
		Y = y;
		
		this.potion = potion;
		index = indexIten;
		this.largura = largura;
		this.altura = altura;  
		
		isAlive = true;

	}
	

	@Override
	public void SimulaSe(int diftime) {

		if(potion){
			if(!GamePanel.instance.CLICK){
				precionou = false;
			}

			if(!precionou){
				if(GamePanel.instance.CLICK){
					if(mouseBoudingBoxColision()){
						setbAction(true);
						precionou = true;
					}
				}
			}
		}
	}
	
	public boolean isbAction() {
		return bAction;
	}
	public void setbAction(boolean bAction) {
		this.bAction = bAction;
	}


	@Override
	public void DesenhaSe(Graphics2D dbg, int xmundo, int ymundo) {
		dbg.drawImage(image, (int) X, (int) Y, largura, altura, null);
	}
	
	public boolean testBoudingBoxColision(Personagem p1){
		if(!isAlive) return false;

		float left1 = X;
		float right1 = X+largura;
		float top1 = Y;
		float bottom1 = Y+altura;

		float left2 = p1.X;
		float right2 = p1.X+p1.L;
		float top2 = p1.Y;
		float bottom2 = p1.Y+p1.A;

		if(bottom1 < top2) return false;
		if(top1 > bottom2) return false;
		if(right1 < left2) return false;
		if(left1 > right2) return false;

		return true;
	}
	
	public boolean mouseBoudingBoxColision()
    {
        float left1 = X;
        float right1 = X+largura;
        float top1 = Y;
        float bottom1 = Y+altura;

        float left2 = GamePanel.instance.MouseX;
        float right2 = GamePanel.instance.MouseX+1;
        float top2 = GamePanel.instance.MouseY;
        float bottom2 = GamePanel.instance.MouseY+1;

        if(bottom1 < top2) return false;
        if(top1 > bottom2) return false;
        if(right1 < left2) return false;
        if(left1 > right2) return false;

        return true;
    }

}
